#include <gtest/gtest.h>

#include "geometry.h"

int main( int argc, char ** argv ) {
    ::testing::InitGoogleTest( &argc, argv );

    return RUN_ALL_TESTS();
}

class SquareTest : public ::testing::Test
{
protected:
    void SetUp() override {
        auto v = std::make_unique<Vertex>( from, from );
        v->insert( new Vertex( from, to ) );
        v->insert( new Vertex( to, to ) );
        v->insert( new Vertex( to, from ) );
        f = std::make_unique<Figure>( std::move( v ) );
    }

    std::unique_ptr<Figure> f;
    const int from = 2;
    const int to = 5;
};

TEST_F( SquareTest, size ) {
    ASSERT_EQ( f->size, 4 );
    // TODO insert new vertexes?
}

TEST_F( SquareTest, isPointIn ) {
    for ( auto x = 0; x < to * 2; ++x )
    {
        for ( auto y = 0; y < to * 2; ++y )
        { ASSERT_EQ( f->isPointIn( Point( x, y ) ), x >= from && x <= to && y >= from && y <= to ); }
    }
}

TEST_F( SquareTest, isCrossingEdge ) {
    auto e = []( int a, int b, int c, int d ) { return Edge( Point( a, b ), Point( c, d ) ); };
    ASSERT_FALSE( f->isCrossing( e( 1, 1, 1, 6 ) ) );
    ASSERT_FALSE( f->isCrossing( e( 1, 6, 6, 6 ) ) );
    ASSERT_FALSE( f->isCrossing( e( 6, 6, 6, 1 ) ) );
    ASSERT_FALSE( f->isCrossing( e( 6, 1, 1, 1 ) ) );

    ASSERT_FALSE( f->isCrossing( e( 6, 3, 4, 0 ) ) );
    ASSERT_FALSE( f->isCrossing( e( 3, 1, 0, 3 ) ) );
    ASSERT_FALSE( f->isCrossing( e( 0, 3, 3, 7 ) ) );
    ASSERT_FALSE( f->isCrossing( e( 3, 7, 7, 4 ) ) );

    ASSERT_TRUE( f->isCrossing( e( 2, 1, 2, 6 ) ) );
    ASSERT_TRUE( f->isCrossing( e( 1, 5, 6, 5 ) ) );
    ASSERT_TRUE( f->isCrossing( e( 5, 6, 5, 0 ) ) );
    ASSERT_TRUE( f->isCrossing( e( 6, 2, 2, 2 ) ) );

    ASSERT_TRUE( f->isCrossing( e( 3, 1, 7, 3 ) ) );
    ASSERT_TRUE( f->isCrossing( e( 3, 6, 7, 3 ) ) );
    ASSERT_TRUE( f->isCrossing( e( 3, 6, 3, 1 ) ) );
}
